<template>
	<view class="open-policy">
		<view class="open-policy-title">
			<text class="open-policy-title-number">{{currentIndex+1}}</text>
			<text class="open-policy-title-name">{{titleList[currentIndex]}}</text>
		</view>
		<view class="open-policy-contain">
			<view class="open-policy-contain-item">
				<u-form :model="form" ref="uForm" :error-type="errorType" :rules="rules">
					<!-- <block v-for="(titleItem,titleIndex) in titleList" :key="`T${titleIndex}`"> -->
					<!-- <template v-if="currentIndex==0"> -->
					<template v-if="titleList[currentIndex]=='代理商关联产品'">
						<u-form-item class="form-item" label="下级代理商" prop="agentNo" label-width="300" required>
							<u-input v-model="agentName" input-align="right" placeholder="请选择" />
							<u-icon slot="right" name="arrow-right" @click="isAgentHandel"></u-icon>
						</u-form-item>
						<u-form-item class="form-item fist-tiem" label="产品政策" prop="policyCode" label-width="300"
							v-if="form.agentNo" required>
							<u-input v-model="policyName" input-align="right" placeholder="请选择" :disabled="true" />
							<u-icon slot="right" name="arrow-right" @click="isPolicyCodePicker = true"></u-icon>
						</u-form-item>
					</template>
					<!-- <template v-if="currentIndex==1"> -->
					<template v-if="titleList[currentIndex]=='激活政策配置'">
						<template v-if="form.existActiveShare == 1">
							<!-- <u-form-item class="form-item" label="奖励金额" prop="activeShare.amount" label-width="300"
								required :rules="rules.amount">
								<u-input v-model="form.activeShare.amount" input-align="right" placeholder="请输入"
									:disabled="true" />
							</u-form-item> -->
							<u-form-item class="form-item"
								:label="`分账金额(${form.activeShare.minShareAmount}-${form.activeShare.maxShareAmount})`"
								prop="activeShare.shareAmount" label-width="300" required :rules="rules.shareAmount">
								<u-input v-model="form.activeShare.shareAmount" input-align="right" placeholder="请输入" />
							</u-form-item>
						</template>
					</template>
					<!-- <template v-if="currentIndex==2"> -->
					<template v-if="titleList[currentIndex]=='达标政策配置'">
						<template v-if="form.existStandardShare == 1">
							<view class="last-item" v-for="(standardItem, standardIndex) in form.standardShare"
								:key="standardIndex">
								<u-form-item class="form-item" label="达标等级" label-width="300" required
									:prop="`standardShare.${standardIndex}.cond`" :rules="rules.cond">
									<u-input v-model="standardItem.cond" input-align="right" placeholder="请输入"
										:disabled="true" />
								</u-form-item>
								<!-- <u-form-item class="form-item" label="考核金额" label-width="300" required
									:prop="`standardShare.${standardIndex}.configure.amount`" :rules="rules.amount">
									<u-input v-model="standardItem.configure.amount" input-align="right"
										placeholder="请输入" :disabled="true" type="digit" />
								</u-form-item> -->
								<template v-if="standardItem.existShare == 1">
									<u-form-item class="form-item"
										:label="`分账金额(${standardItem.configure.minShareAmount}-${standardItem.configure.maxShareAmount})`"
										label-width="300" required
										:prop="`standardShare.${standardIndex}.configure.shareAmount`"
										:rules="rules.shareAmount">
										<u-input v-model="standardItem.configure.shareAmount" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
							</view>
						</template>
					</template>
					<!-- <template v-if="currentIndex==3"> -->
					<template v-if="titleList[currentIndex]=='服务费配置'">
						<template v-if="form.existServiceFeeShare == 1">
							<view class="last-item" v-for="(serviceFeeItem, serviceFeeIndex) in form.serviceFeeShare"
								:key="serviceFeeIndex">
								<u-form-item class="form-item" label="服务费金额" label-width="300" required
									:prop="`serviceFeeShare.${serviceFeeIndex}.amount`" :rules="rules.amount">
									<u-input v-model="serviceFeeItem.amount" input-align="right" placeholder="请输入"
										:disabled="true" type="digit" />
								</u-form-item>
								<u-form-item class="form-item"
									:label="`分账金额(${serviceFeeItem.minShareAmount}-${serviceFeeItem.maxShareAmount})`"
									label-width="300" required :prop="`serviceFeeShare.${serviceFeeIndex}.shareAmount`"
									:rules="rules.shareAmount">
									<u-input v-model="serviceFeeItem.shareAmount" input-align="right" placeholder="请输入"
										type="digit" />
								</u-form-item>
							</view>
						</template>
					</template>
					<!-- <template v-if="currentIndex==4"> -->
					<template v-if="titleList[currentIndex]=='通讯费配置'">
						<template v-if="form.existCommFeeShare == 1">
							<view class="last-item" v-for="(commFeeItem, commFeeIndex) in form.commFeeShare"
								:key="commFeeIndex">
								<u-form-item class="form-item" label="通讯费金额" label-width="300" required
									:prop="`serviceFeeShare.${commFeeIndex}.amount`" :rules="rules.amount">
									<u-input v-model="commFeeItem.amount" input-align="right" placeholder="请输入"
										:disabled="true" type="digit" />
								</u-form-item>
								<u-form-item class="form-item"
									:label="`分账金额(${commFeeItem.minShareAmount}-${commFeeItem.maxShareAmount})`"
									label-width="300" required :prop="`serviceFeeShare.${commFeeIndex}.shareAmount`"
									:rules="rules.shareAmount">
									<u-input v-model="commFeeItem.shareAmount" input-align="right" placeholder="请输入"
										type="digit" />
								</u-form-item>
							</view>
						</template>
					</template>
					<!-- <template v-if="currentIndex==5"> -->
					<template v-if="titleList[currentIndex]=='代理商结算成本'">
						<view class="last-item" v-for="(agentCostItem, agentCostIndex) in form.agentCostScope"
							:key="secondKey('A',agentCostIndex)">
							<view class="title form-item">{{ agentCostItem.dictLabel}}</view>
							<template v-if="agentCostItem.totalType == 1">
								<u-form-item class="form-item" label-width="300" required
									:label="`费率(${agentCostItem.minRate}-${agentCostItem.maxRate}/%)`"
									prop="agentCostRate.posCreditRate" :rules="rules.posCreditRate">
									<u-input v-model="form.agentCostRate.posCreditRate" input-align="right"
										placeholder="请输入" type="digit" />
								</u-form-item>
								<template v-if="agentCostItem.existAdd == 1">
									<u-form-item class="form-item" label-width="300" required
										:label="`笔数费(${agentCostItem.minAdd}-${agentCostItem.maxAdd}/元)`"
										prop="agentCostRate.posCreditAdd" :rules="rules.posCreditAdd">
										<u-input v-model="form.agentCostRate.posCreditAdd" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
							</template>
							<template v-if="agentCostItem.totalType == 2">
								<u-form-item class="form-item" label-width="300" required
									:label="`费率(${agentCostItem.minRate}-${agentCostItem.maxRate}/%)`"
									prop="agentCostRate.posDebitRate" :rules="rules.posDebitRate">
									<u-input v-model="form.agentCostRate.posDebitRate" input-align="right"
										placeholder="请输入" type="digit" />
								</u-form-item>
								<template v-if="agentCostItem.existAdd == 1">
									<u-form-item class="form-item" label-width="300" required
										:label="`笔数费(${agentCostItem.minAdd}-${agentCostItem.maxAdd}/元)`"
										prop="agentCostRate.posDebitAdd" :rules="rules.posDebitAdd">
										<u-input v-model="form.agentCostRate.posDebitAdd" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
								<template v-if="agentCostItem.existLimit == 1">
									<u-form-item class="form-item" label-width="300" required
										:label="`封顶手续费(${agentCostItem.minLimit}-${agentCostItem.maxLimit}/元)`"
										prop="agentCostRate.posDebitLimit" :rules="rules.posDebitLimit">
										<u-input v-model="form.agentCostRate.posDebitLimit" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
							</template>
							<template v-if="agentCostItem.totalType == 3">
								<u-form-item class="form-item" label-width="300" required
									:label="`费率(${agentCostItem.minRate}-${agentCostItem.maxRate}/%)`"
									prop="agentCostRate.ysfRate" :rules="rules.ysfRate">
									<u-input v-model="form.agentCostRate.ysfRate" input-align="right" placeholder="请输入"
										type="digit" />
								</u-form-item>
								<template v-if="agentCostItem.existAdd == 1">
									<u-form-item class="form-item" label-width="300" required
										:label="`笔数费(${agentCostItem.minAdd}-${agentCostItem.maxAdd}/元)`"
										prop="agentCostRate.ysfAdd" :rules="rules.ysfAdd">
										<u-input v-model="form.agentCostRate.ysfAdd" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
							</template>
							<template v-if="agentCostItem.totalType == 4">
								<u-form-item class="form-item" label-width="300" required
									:label="`费率(${agentCostItem.minRate}-${agentCostItem.maxRate}/%)`"
									prop="agentCostRate.scanfRate" :rules="rules.scanfRate">
									<u-input v-model="form.agentCostRate.scanfRate" input-align="right"
										placeholder="请输入" type="digit" />
								</u-form-item>
								<template v-if="agentCostItem.existAdd == 1">
									<u-form-item class="form-item" label-width="300" required
										:label="`笔数费(${agentCostItem.minAdd}-${agentCostItem.maxAdd}/元)`"
										prop="agentCostRate.scanfAdd" :rules="rules.scanfAdd">
										<u-input v-model="form.agentCostRate.scanfAdd" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
							</template>
							<template v-if="agentCostItem.totalType == 5">
								<u-form-item class="form-item" label-width="300" required
									:label="`费率(${agentCostItem.minRate}-${agentCostItem.maxRate}/%)`"
									prop="agentCostRate.vipCreditRate" :rules="rules.vipCreditRate">
									<u-input v-model="form.agentCostRate.vipCreditRate" input-align="right"
										placeholder="请输入" type="digit" />
								</u-form-item>
								<template v-if="agentCostItem.existAdd == 1">
									<u-form-item class="form-item" label-width="300" required
										:label="`笔数费(${agentCostItem.minAdd}-${agentCostItem.maxAdd}/元)`"
										prop="agentCostRate.vipCreditAdd" :rules="rules.vipCreditAdd">
										<u-input v-model="form.agentCostRate.vipCreditAdd" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
							</template>
							<template v-if="agentCostItem.totalType == 6">
								<u-form-item class="form-item" label-width="300" required
									:label="`费率(${agentCostItem.minRate}-${agentCostItem.maxRate}/%)`"
									prop="agentCostRate.vipDebitRate" :rules="rules.vipDebitRate">
									<u-input v-model="form.agentCostRate.vipDebitRate" input-align="right"
										placeholder="请输入" type="digit" />
								</u-form-item>
								<template v-if="agentCostItem.existAdd == 1">
									<u-form-item class="form-item" label-width="300" required
										:label="`笔数费(${agentCostItem.minAdd}-${agentCostItem.maxAdd}/元)`"
										prop="agentCostRate.vipDebitAdd" :rules="rules.vipDebitAdd">
										<u-input v-model="form.agentCostRate.vipDebitAdd" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
								<template v-if="agentCostItem.existLimit == 1">
									<u-form-item class="form-item" label-width="300" required
										:label="`封顶手续费(${agentCostItem.minLimit}-${agentCostItem.maxLimit}/元)`"
										prop="agentCostRate.vipDebitLimit" :rules="rules.vipDebitLimit">
										<u-input v-model="form.agentCostRate.vipDebitLimit" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
							</template>
							<template v-if="agentCostItem.totalType == 7">
								<u-form-item class="form-item" label-width="300" required
									:label="`费率(${agentCostItem.minRate}-${agentCostItem.maxRate}/%)`"
									prop="agentCostRate.qpayRate" :rules="rules.qpayRate">
									<u-input v-model="form.agentCostRate.qpayRate" input-align="right" placeholder="请输入"
										type="digit" />
								</u-form-item>
								<template v-if="agentCostItem.existAdd == 1">
									<u-form-item class="form-item" label-width="300" required
										:label="`笔数费(${agentCostItem.minAdd}-${agentCostItem.maxAdd}/元)`"
										prop="agentCostRate.qpayAdd" :rules="rules.qpayAdd">
										<u-input v-model="form.agentCostRate.qpayAdd" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
							</template>
							<template v-if="agentCostItem.totalType == 10">
								<u-form-item class="form-item" label-width="300" required
									:label="`费率(${agentCostItem.minRate}-${agentCostItem.maxRate}/%)`"
									prop="agentCostRate.jhPayRate" :rules="rules.jhPayRate">
									<u-input v-model="form.agentCostRate.jhPayRate" input-align="right"
										placeholder="请输入" type="digit" />
								</u-form-item>
								<template v-if="agentCostItem.existAdd == 1">
									<u-form-item class="form-item" label-width="300" required
										:label="`笔数费(${agentCostItem.minAdd}-${agentCostItem.maxAdd}/元)`"
										prop="agentCostRate.jhPayAdd" :rules="rules.jhPayAdd">
										<u-input v-model="form.agentCostRate.jhPayAdd" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
							</template>
							<template v-if="agentCostItem.totalType == 11">
								<u-form-item class="form-item" label-width="300" required
									:label="`费率(${agentCostItem.minRate}-${agentCostItem.maxRate}/%)`"
									prop="agentCostRate.jhptPayRate" :rules="rules.jhptPayRate">
									<u-input v-model="form.agentCostRate.jhptPayRate" input-align="right"
										placeholder="请输入" type="digit" />
								</u-form-item>
								<template v-if="agentCostItem.existAdd == 1">
									<u-form-item class="form-item" label-width="300" required
										:label="`笔数费(${agentCostItem.minAdd}-${agentCostItem.maxAdd}/元)`"
										prop="agentCostRate.jhptPayAdd" :rules="rules.jhptPayAdd">
										<u-input v-model="form.agentCostRate.jhptPayAdd" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
							</template>
							<template v-if="agentCostItem.totalType == 12">
								<u-form-item class="form-item" label-width="300" required
									:label="`费率(${agentCostItem.minRate}-${agentCostItem.maxRate}/%)`"
									prop="agentCostRate.zyPayRate" :rules="rules.zyPayRate">
									<u-input v-model="form.agentCostRate.zyPayRate" input-align="right"
										placeholder="请输入" type="digit" />
								</u-form-item>
								<template v-if="agentCostItem.existAdd == 1">
									<u-form-item class="form-item" label-width="300" required
										:label="`笔数费(${agentCostItem.minAdd}-${agentCostItem.maxAdd}/元)`"
										prop="agentCostRate.zyPayAdd" :rules="rules.zyPayAdd">
										<u-input v-model="form.agentCostRate.zyPayAdd" input-align="right"
											placeholder="请输入" type="digit" />
									</u-form-item>
								</template>
							</template>
						</view>
					</template>
					<!-- </block> -->

				</u-form>
			</view>
		</view>
		<view class="open-policy-btn">
			<view class="pre-btn button" v-if="currentIndex!=0" @click="preBtn">
				上一步
			</view>
			<view class="next-btn button" @click="nextBtn">
				{{currentIndex==titleList.length-1?'确定':`下一步${titleList[currentIndex+1]}`}}
			</view>
		</view>
		<u-select v-model="isAgentPicker" :list="agentList" value-name="agentNo" label-name="agentName"
			@confirm="agentConfirm"></u-select>
		<u-select v-model="isPolicyCodePicker" :list="policyCodeList" value-name="policyCode" label-name="policyName"
			@confirm="policyCodeConfirm"></u-select>
	</view>
</template>

<script>
	import {
		getCanOpenList,
		getById,
		open,
		getPolicyConfig,
	} from "@/api/agent-open";
	import {
		getByName as getAgentList
	} from "@/api/agent";
	let scopeObj = {
		// totalType: "",
		minRate: 0.1,
		maxRate: 0.1,
		existAdd: 1,
		minAdd: "",
		maxAdd: "",
		existLimit: 1,
		minLimit: "",
		maxLimit: "",
	};
	export default {
		data() {
			return {
				currentIndex: 0,
				// titleList: ["代理商关联产品", "激活政策配置", "达标政策配置", "服务费配置", "通讯费配置", "代理商结算成本"],
				titleList: ["代理商关联产品", "激活政策配置"],
				agentList: [],
				policyCodeList: [],
				rules: {
					agentNo: [{
						required: true,
						message: '请选择代理商'
					}],
					policyCode: [{
						required: true,
						message: '请选择产品政策'
					}],
					amount: [{
						required: true,
						message: "奖励金额不能为空",
						trigger: "blur"
					}, ],
					shareAmount: [{
						required: true,
						message: "分账金额不能为空",
						trigger: "blur"
					}, ],
					minShareAmount: [{
						required: true,
						message: "最小分账金额不能为空",
						trigger: "blur"
					}, ],
					maxShareAmount: [{
						required: true,
						message: "最大分账金额不能为空",
						trigger: "blur"
					}, ],
					cond: [{
						required: true,
						message: "达标等级不能为空",
						trigger: "blur"
					}, ],
					minRate: [{
						required: true,
						message: "最低费率不能为空",
						trigger: "blur"
					}, ],
					maxRate: [{
						required: true,
						message: "最高费率不能为空",
						trigger: "blur"
					}, ],
					existAdd: [{
						required: true,
						message: "是否存在笔数费不能为空",
						trigger: "blur",
					}, ],
					minAdd: [{
						required: true,
						message: "最低笔数费不能为空",
						trigger: "blur"
					}, ],
					maxAdd: [{
						required: true,
						message: "最高笔数费不能为空",
						trigger: "blur"
					}, ],
					existLimit: [{
						required: true,
						message: "是否存在封顶手续费不能为空",
						trigger: "blur",
					}, ],
					minLimit: [{
						required: true,
						message: "最低封顶手续费不能为空",
						trigger: "blur",
					}, ],
					maxLimit: [{
						required: true,
						message: "最高封顶手续费不能为空",
						trigger: "blur",
					}, ],
				},
				form: {
					existActiveShare: 1,
					activeShare: {
						minShareAmount: 9,
						maxShareAmount: 10,
					},
					existStandardShare: 1,
					standardShare: [],
					existFakeStandard: 1,
					existServiceFeeShare: 1,
					serviceFeeShare: [],
					existCommFeeShare: 1,
					commFeeShare: [],
					agentCostRate: {
						posCreditRate: '',
						posCreditAdd: '',
						posDebitRate: '',
						posDebitAdd: '',
						posDebitLimit: '',
						vipCreditRate: '',
						vipCreditAdd: '',
						vipDebitRate: '',
						vipDebitAdd: '',
						vipDebitLimit: '',
						ysfRate: '',
						ysfAdd: '',
						scanfRate: '',
						scanfAdd: '',
						qpayRate: '',
						qpayAdd: '',
						zyPayRate: ''
					},
					agentCostScope: [],
				},
				agentName: "",
				policyName: "",
				isAgentPicker: false,
				isPolicyCodePicker: false,
				errorType: ['toast'],
				totalTypeOptions: [{
						"dictLabel": "POS贷记卡",
						"dictValue": "1",
					},
					{
						"dictLabel": "POS借记卡",
						"dictValue": "2",
					},
					{
						"dictLabel": "云闪付",
						"dictValue": "3",
					},
					// {
					// 	"dictLabel": "扫码",
					// 	"dictValue": "4",
					// },
					{
						"dictLabel": "VIP贷记卡",
						"dictValue": "5",
					},
					{
						"dictLabel": "VIP借记卡",
						"dictValue": "6",
					},
					{
						"dictLabel": "快捷",
						"dictValue": "7",
					},
					{
						"dictLabel": "汇收银扫码",
						"dictValue": "10",
					},
					{
						"dictLabel": "聚收银扫码",
						"dictValue": "11",
					},
					{
						"dictLabel": "一码聚扫码",
						"dictValue": "12",
					}
				],
			}
		},
		async onLoad(option) {
			this.querySelectList();
			// console.log('titleList', this.titleList)
			// console.log('代理商编号--->' + option.agentNo)
			// console.log(option)
			
			//有代理商编号自动填入
			let agentNo = option.agentNo
			this.initAgent(agentNo)
		},

		methods: {
			async initAgent(agentNo) {
				if(agentNo) { //直接填入代理商编号和政策
					let params = {
						name: agentNo,
					};
					let res = await getAgentList(params);
					let agent = res.data.find(item => item.agentNo === agentNo);
					
					this.form.agentNo = agent.agentNo;
					this.agentName = `${agent.agentName}(${agent.agentNo})`;
					
					// getCanOpenList({
					// 	agentNo
					// }).then((res) => {
					// 	this.policyCodeList = res.data;
					// 	//默认选择第一个
					// 	this.policyName = this.policyCodeList[0].policyName
					// 	this.form.policyName = this.policyCodeList[0].policyName
					// 	this.form.policyCode = this.policyCodeList[0].policyCode
					// });
					
					let res1 = await getCanOpenList({agentNo})
					this.policyCodeList = res1.data;
					//默认选择第一个
					this.policyName = this.policyCodeList[0].policyName
					this.form.policyName = this.policyCodeList[0].policyName
					this.form.policyCode = this.policyCodeList[0].policyCode
					
					let params1 = {
						agentNo: this.form.agentNo,
						policyCode: this.form.policyCode
					};
					this.titleList = ["代理商关联产品", "激活政策配置"]
					getPolicyConfig(params1).then((res) => {
						let {
							data
						} = res;
						this.form = data;
						this.form.agentCostRate = {};
						this.form.agentCostScope = this.totalTypeList(data.agentCostScope);
						// titleList: ["代理商关联产品", "激活政策配置", "达标政策配置", "服务费配置", "通讯费配置", "代理商结算成本"],
						if (data.existActiveShare != 1) this.titleList.splice(1, 1);
						if (data.existStandardShare == 1) this.titleList.push("达标政策配置");
						if (data.existServiceFeeShare == 1) this.titleList.push("服务费配置");
						if (data.existCommFeeShare == 1) this.titleList.push("通讯费配置");
						this.titleList.push("代理商结算成本");
					});
				}
			},
			async isAgentHandel() {
				await this.querySelectList(this.agentName);
				if (this.agentList.length == 0) {
					return this.$tip.toast('暂未搜索到该代理商!')
				}
				this.isAgentPicker = true;
			},
			async querySelectList(query) {
				let params = {
					pageNum: 1,
					pageSize: 40,
					name: query,
				};
				let res = await getAgentList(params);
				this.agentList = res.data.map((item) => {
					if (item.agentName) {
						item.agentName = `${item.agentName}(${item.agentNo})`;
						return item;
					} else {
						item.agentName = `${item.agentNo}(${item.agentNo})`;
						return item;
					}
				});
			},
			// 交易类型转化
			totalTypeList(list) {
				let newList = [];
				if (list) {
					this.totalTypeOptions.forEach((k) => {
						list.forEach((v) => {
							if (v.totalType && v.totalType == k.dictValue) {
								v.dictLabel = k.dictLabel;
								newList.push({
									...v
								});
							}
						});
					});
				} else {
					newList = this.totalTypeOptions.map((k) => {
						let obj = {};
						obj.dictLabel = k.dictLabel;
						obj.totalType = k.dictValue;
						return {
							...obj,
							...scopeObj
						};
					});
				}
				return newList;
			},
			// 下一步
			nextBtn() {
				let params = {
					...this.form
				};
				const index = this.currentIndex;
				console.log(this.titleList)
				if (index < this.titleList.length - 1) {
					this.$refs.uForm.validate(valid => {
						if (valid) {
							return this.currentIndex += 1;
						}
					});
					// this.currentIndex += 1;
				} else {
					this.currentIndex = this.titleList.length - 1;
					params.activeShare =
						params.existActiveShare == 1 ? params.activeShare : {};
					params.standardShare =
						params.existStandardShare == 1 ? params.standardShare : [];
					params.serviceFeeShare =
						params.existServiceFeeShare == 1 ? params.serviceFeeShare : [];
					params.commFeeShare =
						params.existCommFeeShare == 1 ? params.commFeeShare : [];
					console.log({
						params
					})
					// return;
					open(params)
						.then((response) => {
							if (response.code === 200) {
								this.$tip.toast(response.msg)
								setTimeout(() => {
									this.$nav.goBack();
								}, 500);
							}

						})
						.catch((err) => {});
				}

			},
			// 上一步
			preBtn() {
				const index = this.currentIndex;
				this.currentIndex = index == 0 ? 0 : this.currentIndex - 1;
			},
			// 代理商选择
			agentConfirm(e) {
				this.form.agentNo = e[0].value;
				this.agentName = e[0].label;
				const agentNo = e[0].value;
				getCanOpenList({
					agentNo
				}).then((res) => {
					this.policyCodeList = res.data;
				});
			},
			// 政策代码选择
			policyCodeConfirm(e) {
				this.form.policyCode = e[0].value;
				this.policyName = e[0].label;
				let params = {
					agentNo: this.form.agentNo,
					policyCode: this.form.policyCode
				};
				this.titleList = ["代理商关联产品", "激活政策配置"]
				getPolicyConfig(params).then((res) => {
					let {
						data
					} = res;
					this.form = data;
					this.form.agentCostRate = {};
					this.form.agentCostScope = this.totalTypeList(data.agentCostScope);
					// titleList: ["代理商关联产品", "激活政策配置", "达标政策配置", "服务费配置", "通讯费配置", "代理商结算成本"],
					if (data.existActiveShare != 1) this.titleList.splice(1, 1);
					if (data.existStandardShare == 1) this.titleList.push("达标政策配置");
					if (data.existServiceFeeShare == 1) this.titleList.push("服务费配置");
					if (data.existCommFeeShare == 1) this.titleList.push("通讯费配置");
					this.titleList.push("代理商结算成本");
				});
			},
			secondKey(first, second) {
				return `${first}_${second}`
			},
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},

	}
</script>

<style lang="scss">
	.open-policy {
		margin: R(40) R(40) 0;
		padding-bottom: R(30);

		&-title {
			text-align: center;
			width: 100%;
			margin: R(50) 0;

			&-number {
				width: R(55);
				height: R(55);
				// line-height: R(50);
				text-align: center;
				display: inline-block;
				background-color: #4286F5;
				border-radius: 50%;
				border: R(8) solid #98b4f5;
				color: #FFFFFF;
				margin-right: R(20);
			}

			&-name {}
		}

		&-contain {
			margin: R(20) 0;

			.title {
				font-weight: 600;
				font-size: R(30);
				margin-bottom: 0 !important;
				border-radius: R(10) R(10) 0 0 !important;

				&::before {
					content: "";
					position: absolute;
					display: block;
					width: R(10);
					height: R(10);
					border-radius: 50%;
					background-color: #4286F5;
					margin-top: R(20);
					margin-left: R(-20);
				}
			}

			.last-item {
				margin-bottom: R(20);
			}

			&-item {
				.form-item {
					background-color: #FFFFFF;
					border-radius: R(10);
					padding: R(20) R(40);
					margin-bottom: R(1);
				}

				.fist-tiem {
					margin-top: R(30);
				}
			}
		}

		&-btn {
			display: flex;
			justify-content: space-around;
			align-items: center;
			margin-top: R(50);

			.button {
				border-radius: R(50);
				padding: 0 R(30);
				background-color: #4286F5;
				text-align: center;
				height: R(80);
				line-height: R(80);
			}

			.pre-btn {
				width: 30%;
				background-color: #FFFFFF;
			}

			.next-btn {
				width: 60%;
				color: #FFFFFF;
			}
		}
	}

	/deep/ .uni-input-input:disabled {
		color: #bebebe;
	}
</style>